<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" session="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <title>角色管理</title>

    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
    <!-- jqgrid-->
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/custom.ui.jqgrid.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/layer/skin/layer.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/style.css" rel="stylesheet">

    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/jquery.form.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/common.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/i18n/grid.locale-cn.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/minified/jquery.jqGrid.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/layer/layer.js" type="text/javascript"></script>

    <style type="text/css">
        .main h5 a {
            position: absolute;
            right: 20px;
            font-size: 14px;
            bottom: 0px;
            display: inline-block;
            padding: 5px;
        }

        .table_list tbody tr {
            height: 35px;
            text-align: center;
        }
          .left ul li{
			
			*line-height:40px;
			
			*padding-left:20px;
		}
		
		.left ul li a, .left ul li a:hover{
			*color:#fff;
		}
		.panel,.jqGrid_wrapper{
			*+margin-left:270px;
		}
    </style>
</head>
<body view="menu-item-4143">
<jsp:include page="../../top.jsp"></jsp:include>
<div class="right">
    <div class="jqGrid_wrapper">
        <div id="jqGrid_operation" class="jg-grid">
            <h1>角色管理</h1>
            <div class="jqGrid_operation" id="action">
            </div>
        </div>
        <table id="jqGrid"></table>
        <div id="jqGrid_paper"></div>
    </div>
</div>
<script>
    $(document).ready(
            function () {

                $.ajax({
                    type: "POST",
                    async: false,
                    url: '/admin/auth_buttons.action',
                    data: "url=" + window.location.pathname,
                    success: function (data) {
                        data = eval("(" + data + ")");
                        for (var i in data) {
                            var action = data[i].mName;
                            switch (action) {
                                case "角色模板修改":
                                    $("#action").append("<a id=\"edit\"><i class=\"glyphicon glyphicon-edit\"></i>修改</a>");
                                    $("#edit").click(function () {
                                        var sels = jQuery("#jqGrid").jqGrid('getGridParam', 'selarrrow');
                                        if (sels.length == 1) {
                                            layer.open({
                                                type: 2,
                                                title: '<strong>角色模板修改</strong>',
                                                shadeClose: true, //点击遮罩关闭层
                                                area: ['800px', '430px'],
                                                content: '${pageContext.request.contextPath}/admin/roleTemplate_editModelView.action?sid='
                                                + sels.toString(),
                                                btn: ['提交', '取消'],
                                                yes: function (index, layero) {
                                                    var options = {
                                                        success: function (data) {
                                                            data = JSON.parse(data);
                                                            if (data.code == 1) {
                                                                layer.alert(data.msg, function () {
                                                                    layer.closeAll();
                                                                });
                                                            } else {
                                                                layer.alert(data.msg);
                                                            }
                                                            refreshGrid();
                                                        }
                                                    };
                                                    if(confirm("请确认是否修改角色模板，修改将导致所有超级管理员权限变更！" )){
	                                                    $("#layui-layer-iframe" + index).contents().find("#form").ajaxForm(options);
	                                                    $("#layui-layer-iframe" + index).contents().find("#form").submit();
                                                    }
                                                }
                                            });
                                        } else {
                                            layer.alert("请选择记录且只能1条记录", {
                                                icon: 6,
                                                closeBtn: false
                                            });
                                        }
                                    });
                                    break;
                            }
                        }
                    }
                });


                $.jgrid.defaults.styleUI = "Bootstrap";
                $("#jqGrid").jqGrid(
                        {
                            url: "${pageContext.request.contextPath}/admin/roleTemplate_listModel.action",
                            mtype: 'POST',
                            datatype: "json",
                            height: 350,
                            autowidth: true,
                            shrinkToFit: true,
                            rowNum: 10,
                            rowList: [10, 20, 30],
                            colNames: ['序号', '角色名', '类型'],
                            colModel: [{
                                name: "sid",
                                index: "sid",
                                key: true,
                                hidden: true
                            }, {
                                name: 'rtName',
                                index: 'rtName',
                                width: 90
                            }, {
                                name: 'tmpType',
                                index: 'tmpType',
                                formatter: "select",
                                editoptions: {value: "0:平台超级管理员权限模板;1:公司超级管理员权限模板;2:社区超级管理员权限模板;3:锁厂超级管理员权限模板"},
                                width: 90
                            }],
                            sortname: 'sid',
                            rownumbers: true,
                            jsonReader: {
                                root: 'rows',
                                page: "page",
                                total: 'total',
                                records: "records",
                                repeatitems: false
                            },
                            pager: "#jqGrid_paper",
                            viewrecords: true,
                            multiselect: true,
                            hidegrid: false
                        });
            });

    <!--刷新jqGrid表格数据-->
    function refreshGrid() {
        $("#jqGrid").trigger("reloadGrid");
    }

</script>
</body>
</html>
